home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gdevsnfb.c < prev    next >
C/C++ Source or Header  |  1993-05-13  |  3KB  |  117 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevsnfb.c */
  20. /* Sony News frame buffer driver for GhostScript */
  21. #include "gdevprn.h"
  22. /*#include <sys/types.h> problems with ushort! */
  23. typedef    char *    caddr_t;
  24. typedef    long    off_t;
  25. #include <sys/uio.h>
  26. #include <newsiop/framebuf.h>
  27.  
  28. /* The device descriptor */
  29. private dev_proc_open_device(sonyfb_open);
  30. private dev_proc_output_page(sonyfb_output_page);
  31. private dev_proc_close_device(sonyfb_close);
  32. private gx_device_procs sonyfb_procs =
  33.   prn_procs(sonyfb_open, sonyfb_output_page, sonyfb_close);
  34. gx_device_printer gs_sonyfb_device =
  35.   prn_device(sonyfb_procs, "sonyfb",
  36.     102.4,                /* width_10ths */
  37.     103.2,                /* height_10ths */
  38.     100,                /* x_dpi */
  39.     100,                /* y_dpi */
  40.     0,0,0,0,            /* margins */
  41.     1, 0);
  42.  
  43. private int fb_file = -1;
  44. sPrimRect prect;
  45.  
  46. private int
  47. sonyfb_open(gx_device *dev)
  48. {
  49.   sScrType stype;
  50.  
  51.   if(fb_file < 0)
  52.     if((fb_file = open("/dev/fb", 2)) < 0)
  53.       perror("open failed");
  54.     else
  55.       if(ioctl(fb_file, FBIOCGETSCRTYPE, &stype) < 0)
  56.     perror("ioctl failed");
  57.       else
  58.     prect.rect = stype.visiblerect;
  59.  
  60.   return gdev_prn_open(dev);
  61. }
  62.  
  63. private int
  64. sonyfb_close(gx_device *dev)
  65. {
  66.   if(fb_file >= 0)
  67.     {
  68.       close(fb_file);
  69.       fb_file = -1;
  70.     }
  71.   return gdev_prn_close(dev);
  72. }
  73.  
  74. #define FRAME_WIDTH    1024
  75.  
  76. /* Send the page to the printer. */
  77. private int
  78. sonyfb_output_page(gx_device *dev, int num_copies, int flush)
  79. {
  80.   int l, i, byte_width, height;
  81.   unsigned char *bm, *fbs, *fb;
  82.  
  83.   byte_width = (dev->width + 7) / 8;
  84.   height = dev->height;
  85.   bm     = (typeof(bm))prn_dev->mem.base;
  86.  
  87.   prect.refPoint.x = 0;
  88.   prect.refPoint.y = 0;
  89.   prect.ptnRect = prect.rect;
  90.   
  91.   prect.ptnBM.type  = BM_MEM;
  92.   prect.ptnBM.depth = 1;
  93.   prect.ptnBM.width = (byte_width + 1) / 2;
  94.   prect.ptnBM.rect.origin.x = 0;
  95.   prect.ptnBM.rect.origin.y = 0;
  96.   prect.ptnBM.rect.extent.x = byte_width * 8; /* width in 16bit words */
  97.   prect.ptnBM.rect.extent.y = height;
  98.   prect.ptnBM.base = (typeof(prect.ptnBM.base))bm;
  99.   
  100.   prect.fore_color = 1;
  101.   prect.aux_color = 0;
  102.   prect.planemask = FB_PLANEALL;
  103.   prect.transp = 0;
  104.   prect.func = BF_S;
  105.   prect.clip = prect.rect;
  106.   prect.drawBM.type  = BM_FB;
  107.   prect.drawBM.depth = 1;
  108.   prect.drawBM.width = (prect.rect.extent.x + 15) / 16;
  109.   prect.drawBM.rect = prect.rect;
  110.   prect.drawBM.base = 0;
  111.   
  112.   if(ioctl(fb_file, FBIOCRECTANGLE, &prect) < 0)
  113.     perror("rect ioctl failed");
  114.  
  115.   return 0;
  116. }
  117.